package com.neu.his.settleCategory.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.his.commonutils.R;
import com.neu.his.settleCategory.entity.SettleCategory;
import com.neu.his.settleCategory.service.SettleCategoryService;

@CrossOrigin
@RestController
@RequestMapping("/his/settlecategory")
public class SettleCategoryController {
		@Autowired
		private SettleCategoryService settleCategoryService;
//		添加结算类别
		@PostMapping("/addSettleCategory")
		public R addSettleCategory(@RequestBody SettleCategory settleCategory) {
			boolean save = settleCategoryService.addSettleCategory(settleCategory);
			if(save) {
				return R.ok().message("添加成功");
			}else {
				return R.error().message("添加失败");
			}			
		}
//		删除结算类别根据id
		@PostMapping("/deleteSettleCategory")
		public R deleteSettleCategory(int id) {
			boolean del = settleCategoryService.deleteSettleCategory(id);
			if(del) {
				return R.ok().message("删除成功");
			}else {
				return R.error().message("删除失败");
			}				
		}
//		修改结算类别
		@PostMapping("/updateSettleCategory")
		public R updateSettleCategory(@RequestBody SettleCategory settleCategory) {
			boolean upd = settleCategoryService.updateSettleCategory(settleCategory);
			if(upd) {
				return R.ok().message("修改成功");
			}else {
				return R.error().message("修改失败");
			}	
		}
//		分页查询 结算类别 ，支持根据类别名称进行搜索
		@GetMapping("/pageSettleCategory")
		public R pageSettleCategory(int page,int limit,String keyword) {
			page = (page-1)*limit;
			List<SettleCategory> list = settleCategoryService.pageSettleCategory(page, limit, keyword);
			int total = settleCategoryService.pageSettleCategoryTotal(keyword);
			return R.ok().data("list",list).data("total", total);	
		}
		
		
}
